package com.designpatterns.ChainOfResponsibility;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by 41579 on 2017/6/7.
 */
public class ApplicationFilterChain implements FilterChain{
    private List<Filter> filters = new ArrayList<Filter>();
    private Iterator<Filter> flag;
    public void init(){
        flag = filters.iterator();
    }
    public void addFilter(Filter filter){
        filters.add(filter);
    }
    @Override
    public void doFilter(String servletRequest, String servletResponse) {
        if(flag.hasNext()){
            flag.next().doFilter(servletRequest,servletResponse,this);
        }else{
            System.out.println("接受到请求，并发送到servlet进行处理，请求参数是:"+servletRequest+"响应参数是："+servletResponse);
        }
    }
}
